﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using OgilvyOne.DALFactory;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using OgilvyOne.Utility;

namespace OgilvyOne.BLL
{
    /// <summary>
    /// HTML 拼接类
    /// </summary>
    public class ContentHtmlPage
    {
        MenuModel menupage;
        public ContentHtmlPage(MenuModel menupage)
        {
            this.menupage = menupage;
        }

        /// <summary>
        /// 截取字符串长度
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetSubString(string str, int length)
        {
            if (str == null) return "";
            length = length * 2;
            str = FilterHtml(str);
            string temp = str;
            int j = 0;
            int k = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                try
                {
                    if (Regex.IsMatch(temp.Substring(i, 1), @"[\u4e00-\u9fa5]+"))
                    {//是否中文
                        j += 2;
                    }
                    else
                    {
                        j += 1;
                    }
                    if (j <= length)
                    {
                        k += 1;
                    }
                    if (j >= length)
                    {//终止循环
                        return temp.Substring(0, k) + "...";
                    }
                }
                catch (Exception e)
                {
                    Console.Write(e.Message);
                }
            }
            return temp;
        }
        static Regex regex = new Regex("<[^<^>]+>");
        static Regex regexHand = new Regex("&\\w+;");
        public static string FilterHtml(string html)
        {
            return regexHand.Replace(regex.Replace(html, ""), "").Replace("\n", "").Replace("\t", "");
        }

        /// <summary>
        /// 头部导航
        /// </summary>
        /// <returns></returns>
        public static string GetHeader()
        {
            return ((TemplateLabelModel)new TemplateLabelBll().GetLabelMap()["header"]).Value;
        }
        /// <summary>
        /// 公共css/js
        /// </summary>
        /// <returns></returns>
        public static string GetCssjs()
        {
            return ((TemplateLabelModel)new TemplateLabelBll().GetLabelMap()["cssjs"]).Value;
        }
        /// <summary>
        /// 底部导航
        /// </summary>
        /// <returns></returns>
        public static string GetFooter()
        {
            return ((TemplateLabelModel)new TemplateLabelBll().GetLabelMap()["footer"]).Value;
        }
        /// <summary>
        /// 栏目内容年月查询
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public string GetNewsYearMonth(int cid, int year, int month)
        {

            Hashtable yearmap = CmsArticleFrontFactory.create().GetArticleGroupYear(cid);
            return GetYearMonthSearch(yearmap, cid, year, month);

        }
        /// <summary>
        /// 栏目年月查询
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public string GetColumnYearMonth(int cid, int year, int month)
        {
            Hashtable yearmap = CmsArticleFrontFactory.create().GetColumnGroupYear(cid);
            return GetYearMonthSearch(yearmap, cid, year, month);
        }

        public string GetColumnYear(int cid, int year)
        {
            Hashtable yearmap = CmsArticleFrontFactory.create().GetColumnGroupYear(cid);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select name=\"year\" id=\"year\" onchange='query();'>\n");
            foreach (object obj in yearmap.Keys)
            {
                string key = obj.ToString();
                sb.Append("<option value=\"" + key + "\" " + (key == year.ToString() ? "selected='selected'" : "") + ">" + key + "</option>\n");
            }
            sb.Append("</select>\n");
            sb.Append("<script type=\"text/javascript\">\n");
            sb.Append("function query(){\n");
            sb.Append(" location.href = '" + menupage.GetUrl(cid) + "&year='+jQuery('#year').val();\n");
            sb.Append("}\n");

            sb.Append("</script>\n");
            return sb.ToString();
        }



        private string GetYearMonthSearch(Hashtable yearmap, int cid, int year, int month)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<select name=\"year\" id=\"year\" onchange='month(this.value)'>\n");
            foreach (object obj in yearmap.Keys)
            {
                string key = obj.ToString();
                sb.Append("<option value=\"" + key + "\" " + (key == year.ToString() ? "selected='selected'" : "") + ">" + key + "</option>\n");
            }
            sb.Append("</select>\n");
            IList ms = (IList)yearmap[year];
            sb.Append("<select name=\"month\" id=\"month\" onchange='query();'>\n");
            if (ms != null)
            {
                foreach (object obj in ms)
                {
                    string key = obj.ToString();
                    sb.Append("<option value=\"" + key + "\" " + (key == month.ToString() ? "selected='selected'" : "") + ">" + key + "</option>\n");
                }
            }
            sb.Append("</select>\n");
            sb.Append("<script type=\"text/javascript\">\n");
            sb.Append("var years = [];\n");
            foreach (object obj in yearmap.Keys)
            {
                sb.Append("years[" + obj.ToString() + "]=[");
                IList mlist = (IList)yearmap[obj];
                for (int i = 0; i < mlist.Count; i++)
                {
                    sb.Append(mlist[i]);
                    if (i < mlist.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("];\n");
            }
            sb.Append("function query(){\n");
            sb.Append(" location.href = '" + menupage.GetUrl(cid) + "&year='+jQuery('#year').val()+'&month='+jQuery('#month').val();\n");
            sb.Append("}\n");
            sb.Append("function month(year){\n");
            sb.Append(" var monthopts = document.getElementById('month').options;\n");
            sb.Append(" var ms = years[year];\n");
            sb.Append(" monthopts.length=0;\n");
            sb.Append(" for(var i=0;i<ms.length;i++){\n");
            sb.Append(" var opt = new Option(ms[i],ms[i]);\n");
            sb.Append(" monthopts.add(opt);\n");
            sb.Append("}\n");
            sb.Append("query();\n");
            sb.Append("}\n");
            sb.Append("</script>\n");
            return sb.ToString();

        }
        /// <summary>
        /// 新闻列表
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public string GetNewsYearMonthList(int cid, int year, int month)
        {
            StringBuilder sb = new StringBuilder();
            IList datalist = CmsArticleFrontFactory.create().GetNewsList(cid, year, month);
            for (int i = 0; i < datalist.Count; i++)
            {
                CmsArticleModel cm = (CmsArticleModel)datalist[i];
                sb.Append("<li><span class=\"time\">" + GetArticlePubDate(cm) + "</span> <a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></li>");
            }
            return sb.ToString();
        }

        /// <summary>
        /// 文章发布日期
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string GetArticlePubDate(CmsArticleModel model)
        {
            return model.Starttime.Year > 1900 ? model.Starttime.ToString(ConConstants.DATE_FORMAT_STR) : (model.Modifytime.Year > 1900 ? model.Modifytime.ToString(ConConstants.DATE_FORMAT_STR) : model.Addtime.ToString(ConConstants.DATE_FORMAT_STR));
        }
        /// <summary>
        /// 新闻左多图
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public string GetArticleImgs(int aid)
        {
            StringBuilder bigsb = new StringBuilder();
            StringBuilder smallsb = new StringBuilder();
            IList imgs = CmsArticleFrontFactory.create().GetImgs(aid, CmsConstants.IMG_TYPE_COMMON);
            if (imgs.Count > 0)
            {
                bigsb.Append("<div class=\"bigImg\">\n");
                bigsb.Append("<ul>\n");

                if (imgs.Count > 1)
                {
                    smallsb.Append("<div class=\"sImg\">\n");
                    if (imgs.Count > 3)
                    {
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnLeft\"></a>\n");
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnRight\"></a>\n");
                    }
                    smallsb.Append("<div class=\"sInfo\">\n");
                    smallsb.Append("<ul>\n");
                }
                for (int i = 0; i < imgs.Count; i++)
                {
                    CmsArticleImgModel cim = (CmsArticleImgModel)imgs[i];
                    bigsb.Append("<li><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgFileName + "\" width=\"262\"/></li>\n");
                    if (imgs.Count > 1)
                    {
                        smallsb.Append("<li val=\"" + i + "\" class=\"current\"><a href=\"javascript:;\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgSmallFileName + "\" width=\"60\" height=\"54\"/></a></li>\n");
                    }
                }
                bigsb.Append("</ul>\n");
                bigsb.Append("</div>\n");
                if (imgs.Count > 1)
                {
                    smallsb.Append("</ul>\n");
                    smallsb.Append("</div>\n");
                }
            }
            return bigsb.Append(smallsb).ToString();
        }
        /// <summary>
        /// 美味人生 - 普通图 - 列表显示多图 - 获取列表图循环
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public string GetHealthArticleListImgs(int aid)
        {
            StringBuilder bigsb = new StringBuilder();
            StringBuilder smallsb = new StringBuilder();
            IList imgs = CmsArticleFrontFactory.create().GetImgs(aid, CmsConstants.IMG_TYPE_COMMON);
            if (imgs.Count > 0)
            {
                bigsb.Append("<div class=\"bigImg\">\n");
                bigsb.Append("<ul>\n");

                if (imgs.Count > 1)
                {
                    smallsb.Append("<div class=\"sImg\">\n");
                    if (imgs.Count > 3)
                    {
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnLeft\"></a>\n");
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnRight\"></a>\n");
                    }
                    smallsb.Append("<div class=\"sInfo\">\n");
                    smallsb.Append("<ul>\n");
                }
                for (int i = 0; i < imgs.Count; i++)
                {
                    CmsArticleImgModel cim = (CmsArticleImgModel)imgs[i];
                    CmsArticleModel cam = CmsArticleFrontFactory.create().getCmsArticle(cim.ArticleId);
                    bigsb.Append("<li><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.Img_list_file_name + "\" width=\"320\" height=\"172\" alt=\"" + cam.Title + "\"/></li>\n");
                    if (imgs.Count > 1)
                    {
                        smallsb.Append("<li val=\"" + i + "\"" + (i == 0 ? " class=\"current\"" : "") + "><a href=\"javascript:;\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgSmallFileName + "\" width=\"60\" height=\"54\" alt=\"" + cam.Title + "\"/></a></li>\n");
                    }
                }
                bigsb.Append("</ul>\n");
                bigsb.Append("</div>\n");
                if (imgs.Count > 1)
                {
                    smallsb.Append("</ul>\n");
                    smallsb.Append("</div>\n");
                    smallsb.Append("</div>\n");
                }
            }
            return bigsb.Append(smallsb).ToString();
        }
        /// <summary>
        /// 美味人生内容页内容图
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public string GetHealthArticleImgs(int aid)
        {
            StringBuilder bigsb = new StringBuilder();
            StringBuilder smallsb = new StringBuilder();
            IList imgs = CmsArticleFrontFactory.create().GetImgs(aid, CmsConstants.IMG_TYPE_COMMON);
            if (imgs.Count > 0)
            {
                bigsb.Append("<div class=\"Z_YSBConLeft\">\n");
                bigsb.Append("<div class=\"Z_YSBConbigImg\">\n");
                bigsb.Append("<ul>\n");

                if (imgs.Count > 1)
                {

                    smallsb.Append("<div class=\"Z_YSBConsImg\">\n");
                    if (imgs.Count > 3)
                    {
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnLeft\"></a>\n");
                        smallsb.Append("<a href=\"javascript:;\" class=\"btnRight\"></a>\n");
                    }
                    smallsb.Append("<div class=\"Z_YSBConsInfo\">\n");
                    smallsb.Append("<ul>\n");
                }
                for (int i = 0; i < imgs.Count; i++)
                {
                    CmsArticleImgModel cim = (CmsArticleImgModel)imgs[i];
                    CmsArticleModel cam = CmsArticleFrontFactory.create().getCmsArticle(cim.ArticleId);
                    bigsb.Append("<li><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgFileName + "\" width=\"262\" alt=\"" + cam.Title + "\"/></li>\n");
                    if (imgs.Count > 1)
                    {
                        smallsb.Append("<li val=\"" + i + "\" " + (i == 0 ? " class=\"Z_YSBConcurrent\"" : "") + "><a href=\"javascript:;\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgSmallFileName + "\" width=\"60\" height=\"54\" alt=\"" + cam.Title + "\"/></a></li>\n");
                    }
                }
                bigsb.Append("</ul>\n");
                bigsb.Append("</div>\n");

                if (imgs.Count > 1)
                {
                    smallsb.Append("</ul>\n");
                    smallsb.Append("</div>\n");
                    smallsb.Append("</div>\n");
                }
                bigsb.Append(smallsb);
                bigsb.Append("</div>\n");
            }
            return bigsb.ToString();

        }
        /// <summary>
        /// 营养生活 首页热点
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public string GetNutritionTop(int cid, int num, int columnType)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder imgsb = new StringBuilder();
            StringBuilder txtsb = new StringBuilder();
            IList alist = null;
            if (columnType == 0)
            {
                alist = CmsArticleFrontFactory.create().GetHealthArticleList(cid, num);
            }
            else
            {
                alist = CmsArticleFrontFactory.create().GetHealthArticleLists(cid, num);
            }
            sb.Append("<div class=\"h_boxInfo\">\n");
            imgsb.Append("<div id=\"play01\" class=\"h_playbox\">\n");
            imgsb.Append("<div class=\"bigImg\">\n");
            imgsb.Append("<ul>\n");
            for (int i = 0; i < alist.Count; i++)
            {
                CmsArticleModel cm = (CmsArticleModel)alist[i];
                IList ilist = CmsArticleFrontFactory.create().GetImgs(cm.Articleid, CmsConstants.IMG_TYPE_COLUMN_HOTS);
                string img = "";
                if (ilist.Count > 0)
                {
                    img = ((CmsArticleImgModel)ilist[0]).ImgFileName;
                }
                if (img == "")
                {
                    imgsb.Append("<li><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\"><img src=\"/cn/images/yimg.jpg\" width=\"322\" height=\"172\" alt=\"" + cm.Title + "\"/></a></li>\n");
                }
                else
                {
                    imgsb.Append("<li><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + img + "\" width=\"322\" height=\"172\" alt=\"" + cm.Title + "\"/></a></li>\n");
                }
                txtsb.Append("<div" + (i != 0 ? " style=\" display:none;\"" : "") + " class=\"txt\" id=\"txt" + i + "\">");
                txtsb.Append("<div class=\"d1\">\n");
                txtsb.Append("<p><strong><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></strong></p>\n");
                txtsb.Append("<p>" + GetSubString(cm.Content, 50) + "</p>\n");
                txtsb.Append("</div>\n");
                txtsb.Append("<div class=\"d2\">\n");
                txtsb.Append("<span class=\"fr\">" + CommonModel.GetHitsCollsHtml(cm) + "</span>\n");
                txtsb.Append("<img src=\"/cn/images/htag.gif\" />\n");
                if (cm.Tag != null && cm.Tag != "")
                {
                    IList tlist = CmsArticleFrontFactory.create().GetArticleTags(cm.Tag);
                    for (int t = 0; t < tlist.Count; t++)
                    {
                        CmsArticleTagModel tm = (CmsArticleTagModel)tlist[t];
                        txtsb.Append("<a href=\"" + GetTagUrl(tm.TagId) + "\">" + tm.TagName + "</a> ");
                    }

                    //txtsb.Append("<a href=\"#\">禁忌</a> <a href=\"#\">宵夜</a> <a href=\"#\">晚上</a> <a href=\"#\">汤</a>\n");
                }
                txtsb.Append("</div>\n");
                txtsb.Append("<div class=\"d3\">\n");
                txtsb.Append("<a href=\"" + GetCollUrl(cm.Articleid) + "\" class=\"hCollect fr\"  id=\"addcolls" + cm.Articleid + "\">添加至我的收藏</a>\n");
                txtsb.Append("<a href=\"" + menupage.GetArticleUrl(cm) + "\" class=\"hMore\" target=\"" + ConConstants.CONTENT_TARGET + "\">查看详细</a>\n");
                txtsb.Append("</div>\n");

                txtsb.Append("</div>\n");
            }
            imgsb.Append("</ul>\n");
            imgsb.Append("</div>\n");
            imgsb.Append("<div class=\"count\"></div>\n");
            imgsb.Append("</div>\n");
            sb.Append(imgsb.ToString());
            sb.Append(txtsb);
            sb.Append("</div>\n");
            return sb.ToString();
        }

        /// <summary>
        /// 营养生活 栏目热点
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public string GetNutritionColumnTop(int cid, int num)
        {
            ColumnModel cminfo = menupage.GetColumn(cid);
            StringBuilder sb = new StringBuilder();
            IList alist = CmsArticleFrontFactory.create().GetColumnTopArticleList(cid, num);
            if (alist.Count > 0)
            {
                sb.Append("<div class=\"h_boxList\">\n");
                string nimg = "/cn/images_column/Title_" + cid + ".png";
                if (cminfo.Nameimg != null && cminfo.Nameimg != "")
                {
                    nimg = ConConstants.UPLOADFILES_IMAGE_PATH + cminfo.Nameimg;
                }
                sb.Append("<div class=\"pic\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cminfo.Ttile_img + "\" class=\"img\" /><span class=\"picBtn\"><img src=\"" + nimg + "\" /></span></div>\n");
                sb.Append("<div class=\"h_list\">\n");
                sb.Append("<ul>\n");
                for (int i = 0; i < alist.Count; i++)
                {
                    CmsArticleModel cm = (CmsArticleModel)alist[i];
                    sb.Append("<li><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></li>\n");
                }
                sb.Append("</ul>\n");
                sb.Append("<p><a href=\"" + menupage.GetUrl(cminfo) + "\" class=\"hMore\">查看更多</a></p>\n");
                sb.Append("</div>\n");
                sb.Append("</div>\n");
            }
            return sb.ToString();
        }


        /// <summary>
        /// 美味人生 - 内容页 - 中粮奉献
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string GetBrandProducts(CmsArticleModel model)
        {
            StringBuilder sb = new StringBuilder();
            if (model.Mores != null && model.Mores.Brands != null && model.Mores.Brands != "")
            {
                sb.Append("<div class=\"Z_tots\">\n");
                sb.Append("<h3>中粮奉献</h3>\n");
                if (model.Mores.Brands != null && model.Mores.Brands != "")
                {//品牌
                    DataSet ds = new BrandInfoBll().GetList(" STATE=1 and BRAND_ID in(" + model.Mores.Brands + ")");
                    DataTable t = ds.Tables[0];
                    for (int i = 0; i < t.Rows.Count; i++)
                    {
                        sb.Append("<a href=\"" + menupage.GetBrandUrl((int)t.Rows[i]["BRAND_ID"]) + "\" onclick=\"openADUrl('" + menupage.GetBrandUrl((int)t.Rows[i]["BRAND_ID"]) + "','pinpai','" + t.Rows[i]["BRAND_ID"] + "');return false;\"><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + t.Rows[i]["BRAND_LOGO"] + "\" alt=\"" + t.Rows[i]["BRAND_NAME"] + "\" /></a> ");// t.Rows[i]["brand_name"] + ",";
                    }
                }
                //sb.Append("<a href=\"#\"><img src=\"images/Zlogo01.jpg\" alt=\"\" /></a><a href=\"#\"><img src=\"images/Zlogo02.jpg\" alt=\"\" /></a>\n");
                sb.Append("\n</div>\n");

                if (model.Mores.Products != null && model.Mores.Products != "")
                {//产品
                    DataSet ds = new ProductInfoBll().GetList(" STATE=1 and PRODUCT_ID in(" + model.Mores.Products + ")");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        DataTable t = ds.Tables[0];
                        if (ds.Tables[0].Rows.Count > 4)
                        {
                            sb.Append("<div class=\"ZbotmScroll\">\n");

                            sb.Append("<a href=\"javascript:;\" class=\"ZbotmScrollLeft\"></a>\n");
                            sb.Append("<a href=\"javascript:;\" class=\"ZbotmScrollRight\"></a>\n");
                        }
                        else
                        {
                            sb.Append("<div class=\"ZbotmScrollNOlist\">\n");
                        }
                        sb.Append("<div class=\"ZdisPic\">\n");
                        sb.Append("<ul>\n");
                        for (int i = 0; i < t.Rows.Count; i++)
                        {
                            sb.Append("<li><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + t.Rows[i]["PRODUCT_IMG"] + "\" alt=\"" + t.Rows[i]["PRODUCT_NAME"] + "\" width=\"138px\"/></li>\n");
                        }
                        sb.Append("</ul>\n");
                        sb.Append("</div>\n");
                        //if (ds.Tables[0].Rows.Count > 4)
                        {
                            sb.Append("</div>\n");
                        }
                    }
                }

            }
            return sb.ToString();
        }
        /// <summary>
        /// 栏目首页热门标签
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public string GetColumnHotsTags(int cid, int num)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<div class=\"h_boxList\">\n");
            sb.Append("<div class=\"ZLTitle\">热门标签</div>\n");
            sb.Append("<div class=\"h_boxInfo\">\n");
            sb.Append("<div class=\"h_keybox\">\n");
            CmsArticleTagModel q = new CmsArticleTagModel();
            q.State = 1;
            q.IsHots = 1;
            q.ClassIds = cid.ToString();

            IList datalist = CmsArticleTagFactory.create().GetTagList(q);
            for (int i = 0; i < datalist.Count && i < 20; i++)
            {
                CmsArticleTagModel catm = (CmsArticleTagModel)datalist[i];
                sb.Append("<a href=\"" + GetTagUrl(catm) + "\" class=\"z_f" + catm.HotsType + "\">" + catm.TagName + "</a>");
            }
            sb.Append("</div>\n");
            sb.Append("<div class=\"h_keysearch\">\n<form action=\"/cn/search/index.aspx\" id=\"tagsearchform\" target=\"" + ConConstants.CONTENT_TARGET + "\">");
            sb.Append("<input name=\"q\" type=\"text\" class=\"text\" />\n");
            sb.Append("<input name=\"\" type=\"button\" class=\"btn\" value=\"搜索\" onclick=\"doSearch('tagsearchform',1);\"/></form>\n");
            sb.Append("</div>\n");
            sb.Append("</div>\n");
            sb.Append("</div>\n");
            return sb.ToString();
        }
        /// <summary>
        /// 标签URL
        /// </summary>
        /// <param name="tagid"></param>
        /// <returns></returns>
        public string GetTagUrl(int tagid)
        {

            CmsArticleTagModel tag = CmsArticleTagFactory.create().GetTagModel(tagid);
            return GetTagUrl(tag);
        }
        public string GetTagUrl(CmsArticleTagModel tag)
        {

            //CmsArticleTagModel tag = CmsArticleTagFactory.create().GetTagModel(tagid);
            if (tag != null)
            {
                return "javascript:doTagSearch('" + tag.TagName + "','" + tag.TagId + "');";
            }
            return "javascript:;";
        }
        /// <summary>
        /// 添加收藏URL
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public string GetCollUrl(int aid)
        {
            return "javascript:addColl('" + aid + "');";
        }
        /// <summary>
        /// 美味人生 - 列表标签搜索
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public string GetHealthTagSearch(int cid)
        {
            return GetAboutTagSearch(cid);
        }
        public string GetAboutTagSearch(int cid)
        {
            return "<form action=\"/cn/search/index.aspx\" id=\"csearchform\" target=\"" + ConConstants.CONTENT_TARGET + "\"><input type=\"hidden\" name=\"cid\" value=\"" + cid + "\"/><input type=\"text\" name=\"q\" value=\"请输入标签\" onfocus=\"this.value='';\"/> <a href=\"#\" onclick=\"return doSearch('csearchform',1);\"><img src=\"/cn/images/z082504.gif\" alt=\"搜索\" border=\"0\"/></a></form>"; ;
        }

        public string GetHealthArticletop(int cid)
        {

            return "<div id=\"_hitslist" + cid + "\"></div><script type=\"text/javascript\">\n_ajax('/cn/ajaxcontent.aspx','t=41&cid='+" + cid + ",function(res){$('#_hitslist" + cid + "').html(res);\n});\n</script>";
        }

        public string AjaxGetHealthArticletop(int cid)
        {
            StringBuilder sb = new StringBuilder();
            IList pt = CmsArticleFrontFactory.create().GetHealthArticleTop(cid, 9);
            sb.Append("<h2><span><a href=\"" + menupage.GetUrl(42) + "\">查看详细</a></span>人气文章</h2>");
            sb.Append("<ul class=\"txtList\">");
            for (int j = 0; j < pt.Count; j++)
            {
                CmsArticleModel cam = (CmsArticleModel)pt[j];
                sb.Append("<li><span class=\"fr\" id=\"addcolls" + cam.Articleid + "\">" + CommonModel.GetHitsCollsHtml(cam) + " <a href=\"" + GetCollUrl(cam.Articleid) + "\" class=\"hCollect\">添加至我的收藏</a></span><a href=\"" + menupage.GetArticleUrl(cam) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cam.Title + "</a></li>");
            }
            sb.Append("</ul>");
            return sb.ToString();
        }
        public string GetHealthHomeArticleHitsLeft(int cid)
        {

            return "<script type=\"text/javascript\" src=\"/cn/ajaxcontent.aspx?j=2&t=42&cid=" + cid + "\"></script>";
        }
        /// <summary>
        /// 享食之道 左人气文章
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public string AjaxGetHealthHomeArticleHitsLeft(int cid)
        {
            StringBuilder sb = new StringBuilder();
            IList pt = CmsArticleFrontFactory.create().GetHealthArticleTop(cid, 14);//获取人气文章列表（右边）
            sb.Append("<ul class=\"txtList\">");
            for (int j = 0; j < pt.Count; j++)
            {
                CmsArticleModel cam = (CmsArticleModel)pt[j];
                sb.Append("<li><a href=\"" + menupage.GetArticleUrl(cam) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cam.Title + "</a></li>");
            }
            sb.Append("</ul><a href=\"" + menupage.GetUrl(cid) + "\" class=\"hMore\">查看更多</a>");
            return sb.ToString();
        }
        public string GetHealthHotArticle(int cid)
        {
            return "<script type=\"text/javascript\" src=\"/cn/ajaxcontent.aspx?j=2&t=43&cid=" + cid + "\"></script>";
        }
        public string AjaxGetHealthHotArticle(string layerid)
        {
            StringBuilder sb = new StringBuilder();
            IList pt = CmsArticleFrontFactory.create().GetHealthArticleTop(layerid, 15);
            sb.Append("<ul>");
            for (int j = 0; j < pt.Count; j++)
            {
                CmsArticleModel cam = (CmsArticleModel)pt[j];
                sb.Append("<li><a href=\"" + menupage.GetArticleUrl(cam) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\" title=\"" + cam.Title + "\">" + ContentHtmlPage.GetSubString(cam.Title, 11) + "</a></li>");
            }
            sb.Append("<li class=\"more\"><a href=\"" + menupage.GetUrl(ConConstants.HOT_ID) + "\">查看更多</a></li>");
            sb.Append("</ul>");

            return sb.ToString();
        }

        public string AjaxGetStockHtml(bool isbot)
        {
            StringBuilder sb = new StringBuilder();
            IList alist = CmsArticleFrontFactory.create().GetArticleOrderList(ConConstants.ABOUT_STOCK_ID, 0);
            string sid = null;
            for (int i = 0; i < alist.Count; i++)
            {
                sid = null;
                CmsArticleModel cm = (CmsArticleModel)alist[i];
                cm.Mores = CmsArticleFrontFactory.create().GetArticleMore(cm.Articleid);
                if (cm.Mores != null && cm.Mores.GetMoresInfo("stockid") != "")
                {
                    sid = cm.Mores.GetMoresInfo("stockid");
                    try
                    {
                        StockInfoModel sim = StockInfoFactory.create().GetModel(int.Parse(sid));

                        sb.Append("<dl" + (i == (alist.Count - 1) ? " style=\"border-bottom:none\"" : "") + ">\n");
                        sb.Append("<dt><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></dt>\n");
                        sb.Append("<dd class=\"tffa523\">" + sim.Price + "</dd>\n");
                        sb.Append("<dd >" + sim.Per + "%</dd>");
                        sb.Append("</dl>\n");
                    }
                    catch { }
                }




            }
            return sb.ToString();
        }

        public string AjaxGetStockCoHtml()
        {
            StringBuilder sb = new StringBuilder();
            IList alist = CmsArticleFrontFactory.create().GetArticleOrderList(ConConstants.ABOUT_STOCK_ID, 0);
            string sid = null;
            sb.Append("<div class=\"zleft\">\n");
            sb.Append("<img src=\"/cn/images/z_gjtitle01.gif\" alt=\"\" />\n");
            sb.Append("<div class=\"list\">\n");
            for (int i = 0; i < alist.Count; i++)
            {

                CmsArticleModel cm = (CmsArticleModel)alist[i];
                cm.Mores = CmsArticleFrontFactory.create().GetArticleMore(cm.Articleid);
                if (cm.Mores != null && cm.Mores.GetMoresInfo("stockid") != "")
                {
                    sid = cm.Mores.GetMoresInfo("stockid");
                    StockInfoModel sim = StockInfoFactory.create().GetModel(int.Parse(sid));
                    sb.Append("<dl>\n");
                    sb.Append("<dt><a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></dt>\n");
                    sb.Append("<dd class=\"tffa523\">" + sim.Price + "</dd>\n");
                    sb.Append("<dd >" + sim.Per + "%</dd>");
                    sb.Append("</dl>\n");

                }

                if ((i + 1) % 4 == 0)
                {
                    sb.Append("</div></div>\n");
                    sb.Append("<div class=\"zleft\">\n");
                    sb.Append("<img src=\"/cn/images/z_gjtitle01.gif\" alt=\"\" />\n<div class=\"list\">\n");
                }
            }
            sb.Append("<dl style=\"border-bottom:none\">\n");
            sb.Append("<dd>&nbsp;</dd>\n");
            sb.Append("</dl>\n");
            sb.Append("</div>\n");
            sb.Append("</div>\n");
            return sb.ToString();
        }

        public string AjaxGetMap(int aid)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            CmsArticleMapBll mapBll = new CmsArticleMapBll();
            CmsArticleMapModel mapModel = new CmsArticleMapModel();
            IList mapIlist = mapBll.GetMapList(" STATE=1 and ARTICLE_ID = " + aid);
            if (mapIlist.Count > 0)
            { 
                sb.Append("<dl><dt>\n");
                IList ilist = CmsArticleFrontFactory.create().GetImgs(aid, CmsConstants.IMG_TYPE_COMMON);
                if (ilist.Count > 0)
                {
                    CmsArticleImgModel cim = (CmsArticleImgModel)ilist[0];
                    sb.Append("<img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + cim.ImgFileName + "\"  width=\"467\" height=\"317\" border=\"0\" usemap=\"#map\" href=\"#\"/>");
                }
                else
                {
                    sb.Append("<img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + "2011341706344332464.jpg\" width=\"467\"  height=\"317\" />\n");
                }

                //地图点
                sb.Append("<map name=\"map\" id=\"map\">");

                StringBuilder sb2 = new StringBuilder();
                for (int i = 0; i < mapIlist.Count; i++)
                {
                    mapModel = (CmsArticleMapModel)mapIlist[i];
                    sb.Append("<area shape=\"poly\"  coords=\"" + mapModel.MapLat + "\" onfocus=\"this.blur()\" href=\"javascript:;\" onmouseover=\"$('.s_b_box').hide();$('#s_b_" + (i + 1) + "').show();side(" + (i + 1) + ")\" title=\"" + mapModel.MapName + "\" />");
                    //右边公司文字
                    //sb1.Append("<div id=\"s_b_" + (i + 1) + "\" class=\"s_b_box\"" + (i == 0 ? "" : "style=\"display:none\"") + ">");
                    sb1.Append("<div id=\"s_b_" + (i + 1) + "\" style=\"display:none\"  class=\"s_b_box\">");
                    sb1.Append(mapModel.MapContent);
                    sb2.Append(mapModel.MapContent);
                    //sb1.Append("<a class=\"down\">展开全部</a><a  class=\"up\">点击收起</a>");
                    sb1.Append("</div>");
                }
                sb.Append("</map></dt><dd id=\"s_b_0\">");
                sb.Append("<div id=\"s_b_all\" class=\"s_b_box\">");
                sb.Append(sb2.ToString());
                sb.Append("<a class=\"down\">展开全部</a><a  class=\"up\">点击收起</a></div>");
                sb.Append(sb1.ToString());
                sb.Append("</dd></dl>");
                sb.Append("<div class=\"clear\"></div>\n");
            }
            return sb.ToString();
        }
        private string GetColumnLayeridUrl(string[] lid, string name)
        {
            string s = "";
            for (int i = 0; i < lid.Length - 1; i++)
            {
                if (lid[i] != null && lid[i] != "")
                {
                    ColumnModel cm = menupage.GetColumn(int.Parse(lid[i]));
                    if (name != cm.Classname)
                    {
                        s += "<a href=\"" + menupage.GetUrl(cm) + "\">" + cm.Classname + "</a> > ";
                    }
                }
            }
            return s;
        }
        public string AjaxGetBrandBusCompOther(int aid)
        {
            CmsArticleMore more = CmsArticleFrontFactory.create().GetArticleMore(aid);
            StringBuilder sb = new StringBuilder();
            //sb.Append("<div class=\"h_box\">\n");
            sb.Append("<dl class=\"z_xgyw\" style=\"margin-left:0px;\">\n");
            if (more != null)
            {
                if (more.Subsidiary != null && more.Subsidiary != "")
                {
                    sb.Append("<dt>相关业务</dt>\n");
                    IList concacts = CmsArticleFrontFactory.create().GetConcacts(more.Subsidiary);
                    IList cslist = new ArrayList();
                    for (int i = 0; i < concacts.Count; i++)
                    {
                        CmsArticleModel cm = (CmsArticleModel)concacts[i];
                        sb.Append("<dd>" + GetColumnLayeridUrl(menupage.GetColumn(cm.Columnid).Layerid.Replace("1,2,3,133,", "").Split(','), cm.Title) + "<a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></dd>\n");
                        cslist.Add(CmsArticleFrontFactory.create().GetSubsidiary(cm.Articleid));
                    }
                    //sb.Append("<dd><a href=\"#\">粮油食品贸易及物流</a> > <a href=\"#\">蔬菜、水果和坚果加工</a> > 碳酸、果汁、茶与水饮料</dd>\n");
                    //sb.Append("<dd><a href=\"#\">粮油食品贸易及物流</a> > <a href=\"#\">蔬菜、水果和坚果加工</a> > 碳酸、果汁、茶与水饮料</dd>\n");


                     
                    if (cslist.Count > 0)
                    {
                        Hashtable m = new Hashtable();
                        sb.Append("<dt>相关单位</dt>\n");
                        for (int i = 0; i < cslist.Count; i++)
                        {
                            IList cclist = (IList)cslist[i];
                            for (int c = 0; c < cclist.Count; c++)
                            {
                                CmsArticleModel cm = (CmsArticleModel)cclist[c];
                                if (!m.ContainsKey(cm.Articleid))
                                {
                                    sb.Append("<dd>" + GetColumnLayeridUrl(menupage.GetColumn(cm.Columnid).Layerid.Replace("1,2,3,18,99", "").Split(','), cm.Title) + "<a href=\"" + menupage.GetArticleUrl(cm) + "\" target=\"" + ConConstants.CONTENT_TARGET + "\">" + cm.Title + "</a></dd>");
                                    m[cm.Articleid] = cm;
                                }
                            }
                        }
                        //sb.Append("<dd><a href=\"#\">粮油食品贸易及物流</a></dd>\n");
                        //sb.Append("<dd><a href=\"#\">粮油食品贸易及物流</a></dd>\n");


                    }
                }
            }
            sb.Append("</dl>\n");

            sb.Append("<div class=\"clear\"></div>\n");
            if (more != null && more.Brands != null && more.Brands != "")
            {
                DataSet ds = new BrandInfoBll().GetList(" STATE=1 and BRAND_ID in(" + more.Brands + ")");
                DataTable t = ds.Tables[0];

                sb.Append("<div class=\"column\">\n");
                sb.Append("<div class=\"title\">主要品牌</div>\n");
                
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    if (i % 5 == 0)
                    {
                        sb.Append("<div class=\"h_product\">\n");
                    }
                    sb.Append("<dl class=\"h_productList\">\n");
                    sb.Append("<dt><img src=\"" + ConConstants.UPLOADFILES_IMAGE_PATH + t.Rows[i]["BRAND_LOGO"] + "\" width=\"92\" alt=\"" + t.Rows[i]["BRAND_NAME"] + "\"/></dt>\n");
                    sb.Append("<dd><a href=\"" + menupage.GetBrandUrl((int)t.Rows[i]["BRAND_ID"]) + "\" onclick=\"openADUrl('" + menupage.GetBrandUrl((int)t.Rows[i]["BRAND_ID"]) + "','pinpai','" + t.Rows[i]["BRAND_ID"] + "');return false;\">" + t.Rows[i]["BRAND_NAME"] + "</a></dd>\n");
                    sb.Append("</dl>\n");
                    if ((i + 1) % 5 == 0 || i == t.Rows.Count - 1)
                    {
                        sb.Append("</div>");
                    }
                }

                sb.Append("</div>\n");
                sb.Append("</div>\n");
            }
            //sb.Append("</div>\n");
            return sb.ToString();
        }
    }
}
